#!/bin/bash

#PATH
START_SLAVE=/AppServer/subscription/
#VAR
JAVA_OPTS_SLAVE="-Xms300m -Xmx300m -XX:MaxPermSize=128m -XX:ThreadStackSize=128 -XX:NewSize=128m -XX:MaxNewSize=128m -XX:-UseParallelOldGC -XX:SurvivorRatio=4 -Duser.timezone=America/Sao_Paulo -Dsun.rmi.dgc.client.gcInterval=360000 -Dsun.rmi.dgc.server.gcInterval=360000 -XX:+HeapDumpOnOutOfMemoryError -Djava.net.preferIPv4Stack=true -XX:ThreadStackSize=160"

#restart slaves
clear
echo -e " \n"
echo -e "* restart_Slave_Subscription *\n"
read -p "Aperte [Enter] para iniciar"

#finalizando os slaves

echo -e 'Finalizando os slaves...'
ps aux | grep 'sb-slave' | grep -v 'grep' | awk '{print $2}'| xargs sudo kill -9  >> /var/log/subscription/subscription-slave.log 2>&1
sleep 2
#processo start dos slaves
clear
echo -en 'Digite o numero de Slaves a serem startados.:\n'
read 'a'

for ((i=1; i <= $a; i++))
do
  $(java $JAVA_OPTS_SLAVE -jar $START_SLAVE/sb-slave-remote-chuncking-1.0.0.jar >>/var/log/subscription/subscription-slave.log 2>&1 &)
  echo "Startando o Slave $i..."
done
echo""
echo "Foram startados $(ps aux | grep sb-slave| grep -v grep| wc -l) slaves com sucesso.."

